<?php

namespace App\Admin\Controllers;

use App\Notice;
use Illuminate\Http\Request;

class NoticeController extends Controller
{
    //
    public function index()
    {
        $notices = Notice::OrderBY('created_at', 'desc')->paginate(10);
        return view('admin.notice.index', compact('notices'));
    }

    public function create()
    {
        return view('admin.notice.add');
    }

    public function store()
    {
        $this->validate(\request(), [
            'title' => 'required | string',
            'content' => 'required | string'
        ]);

        $params = \request(['title', 'content']);
        $notice = Notice::create($params);

        //发通知
        dispatch(new \App\Jobs\SendMessage($notice));

        return redirect('/admin/notices');
    }
}
